<?php

namespace App\Repositories;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use InfyOm\Generator\Common\BaseRepository;

/**
 * Class UserRepository
 * @package App\Repositories
 * @version August 28, 2017, 3:11 pm CST
 *
 * @method User findWithoutFail($id, $columns = ['*'])
 * @method User find($id, $columns = ['*'])
 * @method User first($columns = ['*'])
 */
class UserRepository extends BaseRepository
{
    /**
     * @var array
     */
    protected $fieldSearchable = [

    ];

    /**
     * Configure the Model
     **/
    public function model()
    {
        return User::class;
    }

    public function getUserDetail($user_id)
    {
        $user = User::where('id', $user_id)->first();
        $work_type_names = "";

        if (!empty($user->work_type_ids)) {
            $ids = json_decode($user->work_type_ids);
            $work_type = DB::table('sc_work_type')->whereIn('id', $ids)->pluck('name', 'id');
            foreach ($ids as $key => $id) {
                $work_type_names .= $work_type[$id] . ';';
            }
            $work_type_names = substr($work_type_names, 0, -1);
        }
        $user->work_type_names = $work_type_names;
        return $user;
    }
}
